/**   
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-03-25 22:54:13  
 * Copyright (c) 2015- -版权所有     
 */

package com.joysuch.wwyt.bp.repository;

import java.util.List;

import com.joysuch.wwyt.bp.entity.BpAccident;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

/**
 * BpAccidentDao
 *
 */
public interface BpAccidentDao extends JpaRepository<BpAccident, Long>, QuerydslPredicateExecutor<BpAccident> {
    public Page<BpAccident> findAll(Specification<BpAccident> spec, Pageable pageable);

    public BpAccident save(BpAccident bean);

    public void delete(BpAccident bean);

    @Query("select count(m) from BpAccident m where code = ?1")
    long countOfCode(String code);

    @Query("select count(m) from BpAccident m where code = ?1 and id != ?2")
    long countOfCodeExcludeId(String code, Long id);

    @Query("select name from BpAccident where id = ?1")
    public String getNameById(Long id);

    @Query("select id from BpAccident where code like %?1%")
    public List<Long> getIdByCodeContains(String codeOrName);

    @Query("select id from BpAccident where departId=?1")
    public List<Long> getIdsByDepartId(Long accidentDepartId);
}
